<template>
  <div>
    <h2>人员列表：</h2>
    <h4 style="color: orange">count 组件求和值为：{{sum}}</h4>
    <input v-model="name" placeholder="输入姓名">
    <button @click="addPerson">添加</button>
    <ol>
      <li v-for="person in personList" :key="person.id">
        {{ person.name }}
      </li>
    </ol>
  </div>
</template>

<script>
import {nanoid} from "nanoid"

export default {
  name: "PersonList",
  data() {
    return {
      name: '',
    }
  },
  computed:{
    personList(){
      return this.$store.state.personOption.personList
    },
    sum(){
      return this.$store.state.countOption.sum
    }
  },
  methods: {
    addPerson() {
      //this.personList.unshift()
      const person = {id: nanoid(), name: this.name}
      this.$store.commit('personOption/ADD_PERSON', person)
      this.name = ''
    },

  }

}
</script>

<style scoped>

</style>